package huawei;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 最大社交距离
 */
public class Q89 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int seatsNum = sc.nextInt(); // 座位
        sc.nextLine();
        String string = sc.nextLine();
        List<Integer> operations = Arrays.stream(string.substring(1, string.length() - 1).split(",")).map(String::trim).map(Integer::parseInt).collect(Collectors.toList());

        Set<Integer> seted = new HashSet<>();

        for (Integer operation : operations) {
            if (operation == 1) {
                if (seted.isEmpty()) {
                    seted.add(0);

                } else if (seted.size() == seatsNum) {
                    System.out.println(-1);// 坐满了
                } else {
                    int seat = 1, maxDist = -1;
                    int pre = -1;
                    // 遍历所有的位置

                    for (int i = 0; i < seatsNum; i++) {
                        if (seted.contains(i)) {
                            pre = i;
                        } else {
                            int d = 0; // 距离
                            if (pre == -1) {
                                d = i;
                            } else {
                                d = (i - pre + 1) / 2;
                            }

                            if (d > maxDist) {
                                maxDist = d;
                                seat = pre + d;
                            }
                        }
                    }

                    if (!seted.contains(seatsNum - 1)) {
                        // 左边没有边界
                        int lastL = 0;
                        for (int i = seatsNum - 1; i >= 0 ; i--) {
                            if (seted.contains(i)) {
                                lastL = i;
                                break;
                            }
                        }

                        if (seatsNum - lastL - 1 > maxDist) {
                            seat = seatsNum - 1;
                        }
                    }
                }
            }
        }

//        System.out.println(seatsNum + " " + operation);
    }
}
